<?php
/**	
*	FILENAME: 		/server_app/courses.php
*	DESCRIPTION:	This backend script produces a JSON response representing a listing of the current registered courses of a student.
*	AUTHOR:			Casey Burkhardt
*	VERSION:		1.0.0
*	LAST MODIFIED:	12/30/2009
**/

require_once($_SERVER['DOCUMENT_ROOT'] . "/libraries/functions.php");
require_once($_SERVER['DOCUMENT_ROOT'] . "/libraries/novasis.php");

enforceSSL();

$studentID = $_POST["studentID"];
$pin = $_POST["pin"];

if ((strlen($studentID) == 0) || (strlen($pin) == 0)) {
	$response["response_type"] = "error";
	$response["error_desc"] = "Student ID or PIN not provided.";
	echo json_encode($response);
	die();
} else {
	// Create a NOVASIS session with the student ID and pin provided.
	$sessionData = getNOVASISSession($studentID, $pin);

	// Validate the session.
	if ($sessionData === FALSE) {
		$response["response_type"] = "error";
		$response["error_desc"] = "Invalid NOVASIS login information provided.";
		echo json_encode($response);
		die();
	} else {
		$termData = getCurrentTermID($sessionData);
		// Validate the data result.
		if ($termData === FALSE) {
			$response["response_type"] = "error";
			$response["error_desc"] = "Unable to obtain current term data.";
			echo json_encode($response);
			die();
		} else {
			// Encode and return the course data.
			$response["response_type"] = "success";
			$response["current_term_id"] = $termData["term_id"];
			$response["current_term_name"] = $termData["term_name"];
			echo json_encode($response);
			die();
		}
	}
}

?>